<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
cfc('core')->checklogin('jy_jdpm/member.index/');
$return=array();
set_html('title','订单-'.$this->plugin_setting('basic')['title']);
if($_RQ['op']=='list'){
	if($_RQ['st']!=0 && !$_RQ['st']){
		$_RQ['st']='11';
	}
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'plugin_name'=>'jy_jdpm');
	if($_RQ['st']=='11'){
		$return['st']=11;
	}
	if($_RQ['st']=='0'){
		$params['status']=0;
		$return['st']=0;
	}
	if($_RQ['st']=='1'){
		
		$params['status']=1;
		$return['st']=1;
	}
	if($_RQ['st']=='2'){
		
		$params['status']=2;
		$return['st']=2;
	}
	if($_RQ['st']=='10'){
		$params['status']=10;
		$return['st']=10;
	}
	if($_RQ['st']=='-1'){
		$params['status']=-1;
		$return['st']=-1;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_weishop_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$v){
		$v['createtime']=date('Y/m/d H:i:s',$v['createtime']);
		$v['deftime1']=date('Y/m/d H:i:s',$v['deftime1']);		
		$good=pdo_get('jy_jdpm_goods',array('id'=>$v['goodsid']),array('images','title'));
		$images=explode('|',$good['images']);
		$v['image']=tomedia($images['0']);
		$v['name']=$good['title'];
		if($v['deftime1st']){
			$v['statusname']='买家违约';
		}elseif($v['deftime2st']){
			$v['statusname']='卖家违约';
		}else{
			$v['statusname']=$this->ordertypes()[$v['status']];
		}
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='receive'){
	$orderid=trim($_RQ['orderid']);
	if(!$orderid){
		exi('请先选择要收货的订单！','error');
	}
	$order=pdo_get('jy_weishop_order',array('id'=>$orderid,'mid'=>$_SESSION['uid']));
	if(!$order){
		exi('指定订单不存在！','error');
	}
	if($order['status']!=2){
		exi('订单状态错误！无法确认收货！','error');
	}
	$orderset=plugin_set2('order');
	$orderset['endtime']=$orderset['endtime']?$orderset['endtime']:3;
	$deftime10=$orderset['endtime']*24*3600 + TIMESTAMP;
	pdo_update('jy_weishop_order',array('status'=>3,'finishtime'=>time()),array('id'=>$orderid));
	pdo_update('jy_jdpm_order',array('status'=>3),array('orderid'=>$orderid));
	exi('确认收货成功！','','jy_jdpm/member.order/list');
}